package com.itheima.health.controller;


import com.itheima.health.common.MessageConst;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.ChecksetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/checkgroup")
@RestController
@Api(tags = "检查项组接口")
@Slf4j
public class CheckGroupController {
        @Autowired
        private CheckGroupService checkGroupService;

         @Autowired
         private ChecksetmealService checksetmealService;


    /**
     * 检查项组分页查询
     * @return
     */
    @GetMapping("/findPage")
    public Result checkgroup(QueryPageBean queryPageBean){
        //TODO 调用service层
        PageResult pageResult = checkGroupService.getInquire(queryPageBean);

        return new Result(true,MessageConst.ACTION_SUCCESS,pageResult);
    }


    /**
     * 新增数据
     * @return
     */
    @ApiOperation(value = "新增检查组接口")
    @PostMapping("/add")
    public Result add(String checkitemIds,@RequestBody CheckGroup checkGroup){
    //调用service层进行新增
        checkGroupService.updata(checkGroup,checkitemIds);

        return new Result(true,MessageConst.ACTION_SUCCESS,null);
    }


    /**
     * 查询回显检查组数据
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result findById( Integer id){
        log.info("id参数值: {}",id);
        //调用service层
        CheckGroup checkGroup = checkGroupService.getbyID(id);

        return new Result(true,MessageConst.ACTION_SUCCESS,checkGroup);
    }

    /**
     * 查询回显检查组数据
     * @param id
     * @return
     */
    @GetMapping("/findCheckItemIdsByCheckGroupId")
    public Result findCheckItemIdsByCheckGroupId( Integer id){
        log.info("id参数值: {}",id);
        //调用service层
        List<Integer> ids = checkGroupService.getbycheckitmlID(id);

        return new Result(true,MessageConst.ACTION_SUCCESS,ids);
    }

    /**
     * 根据id删除检查组数据
     * @param id
     * @return
     */
    @PostMapping("/deleteCheckGroupitemById")
    public Result deleteCheckGroupitemById( Integer id){
        //调用service层
        checkGroupService.deletedata(id);

        return new Result(true,MessageConst.ACTION_SUCCESS,null);
    }

    /**
     * 更新检查组数据
     * @return
     */
    @PostMapping("/edit")
    public Result edit(@RequestBody CheckGroup checkGroup,Integer[] checkitemIds ){
        //调用service层更新数据
        PageResult pageResult = checkGroupService.updateDATE(checkGroup,checkitemIds);


        return new Result(true,MessageConst.ACTION_SUCCESS,null);
    }

    /**
     * 查询所有新增套餐列表的检查组
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll(){
        //TODO 调用service层
        List<CheckGroup> checkGroup = checksetmealService.insetSetmeal();

        return new Result(true,MessageConst.ACTION_SUCCESS,checkGroup);
    }



}
